/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */

var deleteNode = function (head, val) {
    if (!head) {
        return null
    }
    let dummy = new ListNode()
    dummy.next = head
    let cur = head
    let pre = dummy
    while (cur) {
        if (cur.val === val) {
            pre.next = cur.next
            return dummy.next
        } else {
            pre = cur
            cur = cur.next
        }
    }
    return dummy.next
};